package com.homedo.odin.solution.service;

import com.dangdang.ddframe.rdb.sharding.id.generator.IdGenerator;
import com.dangdang.ddframe.rdb.sharding.id.generator.self.IPIdGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.homedo.core.common.base.service.BaseService;
import com.homedo.odin.solution.contract.mng.request.comment.UserCommentListRequestBean;
import com.homedo.odin.solution.dao.UserCommentMapper;
import com.homedo.odin.solution.model.dto.PageBean;
import com.homedo.odin.solution.model.entity.UserComment;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p> 用户评论表 服务实现类 </p>
 *
 * @author HarveyDing
 * @since 2018-03-08
 */
@Service
public class UserCommentServiceImpl extends BaseService<UserCommentMapper, UserComment> {

    @Autowired
    private UserCommentMapper userCommentMapper;

    public UserComment selectOne(Long commentId) {
        UserComment comment = new UserComment();
        comment.setCommentId(commentId);
        return userCommentMapper.selectOne(comment);
    }

    public PageInfo<UserComment> queryUserCommentListByParm(String columnTitle, Integer type, Integer replyStatus,
            Integer auditStatus, Date createStartTime, Date createEndTime, PageBean pageBean) {
        PageHelper.startPage(pageBean.getCurrentPage(), pageBean.getPageSize());
        return new PageInfo<UserComment>(userCommentMapper.queryUserCommentListByParm(columnTitle, type,
                replyStatus, auditStatus, createStartTime, createEndTime));
    }

    public PageInfo<UserComment> queryUserCommentListByParm(UserCommentListRequestBean userCommentListRequestBean,
            Date createStartTime, Date createEndTime) {
        PageHelper.startPage(userCommentListRequestBean.getPageNum(), userCommentListRequestBean.getPageSize());
        return new PageInfo<UserComment>(
                userCommentMapper.queryUserCommentListByParm(userCommentListRequestBean.getColumnTitle(),
                        userCommentListRequestBean.getType(),
                        userCommentListRequestBean.getReplyStatus(),
                        userCommentListRequestBean.getAuditStatus(),
                        createStartTime,
                        createEndTime));
    }


    public void auditUserCommentSuccess(Long commentId) {
        userCommentMapper.auditUserCommentSuccess(commentId);
    }

    public void updateUserComment(Long commentId) {
        userCommentMapper.updateUserComment(commentId);
    }

    public void replyUserComment(UserComment userComment) {
        userCommentMapper.updateById(userComment);
    }

    public Long addUserComment(UserComment userComment) {
        IdGenerator ipIdGenerator = new IPIdGenerator();
        Long commentId = (Long) ipIdGenerator.generateId();
        userComment.setCommentId(commentId);
        userCommentMapper.insert(userComment);
        return commentId;
    }

    public PageInfo<UserComment> queryUserCommentListByColumnId(Long columnId, Integer userId, PageBean pageBean) {
        PageHelper.startPage(pageBean.getCurrentPage(), pageBean.getPageSize());
        return new PageInfo<UserComment>(
                userCommentMapper.queryUserCommentListByColumnId(columnId,
                        userId));
    }

    public void addUserCommentLike(Long commentId) {
        userCommentMapper.addUserCommentLike(commentId);
    }
}
